An operating system (OS) generally provides two (2) categories of execution space. The first category is the user space for executing general applications, web browsers, programs word processors, and user programs. The second category is the kernel, which is a protected region of memory execution space inside of a computer. The kernel arbitrates access to the hardware and allows sharing of resources between user space programs.
A system call (syscall) is a common method for applications to request operating system controlled services and resources. Syscalls are an integral part of how an application takes advantage of an operating system, and have standardized interfaces. A syscall is how a program requests a service from the kernel. This may include hardware related services (e.g. accessing the hard disk), creating and executing new processes, and communicating with integral kernel services (e.g., scheduling). Syscalls provide an interface between a process and the operating system.
Many operating systems (e.g., the Linux® OS) implement a system call (syscall) by placing its associated syscall number and its related syscall arguments in pre-defined central processing unit (cpu) registers or memory locations, and then executing a cpu trap instruction. An example of a trap instruction is a subroutine call that interrupts the normal execution flow of the cpu, saves the current execution context, vectors to a trap handler location, reads the system call number and associated arguments, puts the processor in a privilege mode, and performs the corresponding requested service. Nominally, each syscall is triggered individually, such that each syscall requires its own trap instruction.
A trap instruction generally causes the cpu to slow down. Caches are flushed, instruction caches are invalidated, and instructions are halted in order to accommodate the trap instruction. Generally, a trap instruction is an impediment to the optimization of a program's execution. If a process requires a lot of system calls, and therefore a lot of traps, this can result in significant performance degradation of the program's execution.